package com.rz.htk.product.controller;

import com.rz.core.kit.RespKit;
import com.rz.core.resp.ResultResp;
import com.rz.htk.product.entity.Product;
import com.rz.htk.product.entity.vo.PrdDeleteParam;
import com.rz.htk.product.service.IProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName ProductController
 * @Description 产品controller
 * @Author maweiyue
 * @Date 2019/3/26 20:37
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private IProductService productService;

    @PostMapping("/getPage")
    public ResultResp getPage(@RequestBody Product product){
        return RespKit.success(productService.getPage(product));
    }

    @PostMapping("/saveProduct")
    public ResultResp saveProduct(@RequestBody Product product){
        return RespKit.success(productService.saveProduct(product));
    }

    @PostMapping("/batchDelete")
    public ResultResp batchDelete(@RequestBody PrdDeleteParam prdDeleteParam){
        return RespKit.success(productService.batchDelete(prdDeleteParam));
    }

    @PostMapping("selectAll")
    public ResultResp selectAll(){
        return RespKit.success(productService.selectAllProduct());
    }

    @PostMapping("selectProductDetails")
    public ResultResp selectProductDetails(){
        return RespKit.success(productService.selectProductDtails());
    }

    @PostMapping("selectProductDetailsByCountry/{code}")
    public ResultResp selectProductDetailsByCountry(@PathVariable String code){
        return RespKit.success(productService.selectProductDtailsByCountry(code));
    }

    /**
     * 根据目的地国家代码获取适合的产品列表
     * @param country 国家两字节代码
     * @return
     */
    @PostMapping("listProductByCountry/{country}")
    public ResultResp selectProductByCountry(@PathVariable String country){
        return RespKit.success(productService.listProductByCountry(country));
    }

    @PostMapping("getTemplateByPrdId/{prdId}")
    public ResultResp getTemplateByPrdId(@PathVariable Integer prdId){
        return RespKit.success(productService.getTemplateByPrdId(prdId));
    }

    @PostMapping("getAll")
    public ResultResp getAll(){
        return RespKit.success(productService.listAll());
    }
}
